1
00:00:00,510 --> 00:00:06,240
Today I'm going to introduce a programming structure called the Wild Loop, also called Wild Do Loop.

2
00:00:06,240 --> 00:00:09,480
And we're going to make a rotating coin by using that loop.

3
00:00:09,480 --> 00:00:14,460
And we're also going to add power to the coin just because powers are cool and you can jump real high,

4
00:00:14,460 --> 00:00:14,990
too.

5
00:00:15,000 --> 00:00:16,980
So let's go ahead and get started with that.

6
00:00:18,590 --> 00:00:23,570
I certainly to start with an empty world and then I'm going to save the coin off so that I can use it

7
00:00:23,570 --> 00:00:24,410
in my game.

8
00:00:24,410 --> 00:00:29,480
But I want to experiment in a world that's not my game in case I mess something up.

9
00:00:29,480 --> 00:00:30,710
That's good practice.

10
00:00:30,710 --> 00:00:32,420
So let's go to part.

11
00:00:32,840 --> 00:00:37,310
Hit your little arrow, add a cylinder, and this is going to be our coin.

12
00:00:37,790 --> 00:00:39,470
So let's call it coin.

13
00:00:42,290 --> 00:00:43,000
Nice.

14
00:00:43,010 --> 00:00:45,680
Let's make the brick color of that coin yellow.

15
00:00:45,710 --> 00:00:46,780
There we go.

16
00:00:46,790 --> 00:00:51,320
Let's make the material metal and hit an m and then down arrow one.

17
00:00:51,410 --> 00:00:52,580
Now it's metal.

18
00:00:52,910 --> 00:01:00,020
It's good down to the size and we'll make it 0.2 by two by two.

19
00:01:00,050 --> 00:01:00,590
There.

20
00:01:00,590 --> 00:01:01,520
That's very coin.

21
00:01:01,520 --> 00:01:04,400
Like, let's move it up out of the ground.

22
00:01:05,970 --> 00:01:09,540
Cool and then anchor it.

23
00:01:10,350 --> 00:01:15,060
Anchored So don't fall can collide off so it doesn't stop us when we run into it.

24
00:01:15,750 --> 00:01:18,000
Also for orientation.

25
00:01:18,000 --> 00:01:19,300
Let's take a look at this real quick.

26
00:01:19,320 --> 00:01:21,090
This is how we're going to make it spin.

27
00:01:21,090 --> 00:01:28,410
So these are the axes of orientation, the axes of rotation, I should say, the X, Y and the Z.

28
00:01:28,440 --> 00:01:31,620
We're going to rotate this coin around the Y axis.

29
00:01:31,620 --> 00:01:36,660
If I change the Y to 30, we're going to get a 30 degree rotation of our coin.

30
00:01:36,990 --> 00:01:37,740
There we go.

31
00:01:37,740 --> 00:01:39,860
So you can see how we're going to program this.

32
00:01:39,870 --> 00:01:44,460
Let's go ahead and do a control Z to put that back and we'll start coding.

33
00:01:44,460 --> 00:01:48,210
Go to your coin, hit the plus, add a script.

34
00:01:48,210 --> 00:01:49,800
We'll call this rotate.

35
00:01:50,670 --> 00:01:52,020
All right, so got rotate.

36
00:01:52,500 --> 00:01:56,130
And then in the rotate script, I can make this a bigger right.

37
00:01:58,430 --> 00:02:00,380
Get a variable for your coin.

38
00:02:00,530 --> 00:02:04,160
Local coin equals script parent.

39
00:02:04,580 --> 00:02:08,810
And then we're going to make a function, local function, we'll call that rotate.

40
00:02:10,160 --> 00:02:10,520
Right?

41
00:02:10,520 --> 00:02:14,540
And in the rotate function we're going to add a while loop.

42
00:02:14,540 --> 00:02:22,460
Now while loops repeat while a condition is true, we want the coin to continue to rotate until it's

43
00:02:22,460 --> 00:02:23,270
destroyed.

44
00:02:23,270 --> 00:02:31,160
So I am going to write true and that's going to make the y loop run forever or until it's destroyed.

45
00:02:31,510 --> 00:02:31,720
Right.

46
00:02:31,820 --> 00:02:34,490
So what we need to do is get our coin.

47
00:02:34,490 --> 00:02:42,380
Every time we loop through this, we'll get the orientation and then set it equal to the coin's old

48
00:02:42,380 --> 00:02:52,580
orientation plus a vector three new and then I write zero, five and zero.

49
00:02:52,610 --> 00:02:55,610
I need to make this smaller so we can see it all in the screen.

50
00:02:55,850 --> 00:02:56,450
Cool.

51
00:02:56,480 --> 00:02:57,620
What is this doing?

52
00:02:57,650 --> 00:03:01,850
It's taking the old orientation, which is three numbers an X, Y and Z.

53
00:03:01,850 --> 00:03:06,440
So we need the vector three in order to hold an x, y and z.

54
00:03:06,440 --> 00:03:08,480
I only want to change it on the y.

55
00:03:08,480 --> 00:03:10,160
So I'm making these zero.

56
00:03:10,160 --> 00:03:14,000
So we're essentially adding the x to the x, the Y or the Y, the z to the z.

57
00:03:14,330 --> 00:03:16,280
The Y is the only thing changing.

58
00:03:16,280 --> 00:03:22,790
But we also have to put a delay in this loop so that it doesn't crash our system.

59
00:03:22,790 --> 00:03:23,000
Right.

60
00:03:23,000 --> 00:03:24,980
This will run really, really, really fast.

61
00:03:24,980 --> 00:03:26,420
I'll use up all the resources.

62
00:03:26,420 --> 00:03:35,870
Boom, our system will freeze the weight with the no number is about 0.029 or 0.0 3 seconds.

63
00:03:36,320 --> 00:03:39,020
If you put no number in it, it's going to look like this.

64
00:03:39,920 --> 00:03:43,460
So some people will go like this thinking that that's a faster weight.

65
00:03:43,460 --> 00:03:44,840
It's not right.

66
00:03:44,840 --> 00:03:47,960
This is this is as fast as it gets.

67
00:03:48,440 --> 00:03:52,490
So let's call our function and see what we have.

68
00:03:52,610 --> 00:03:55,040
So we're not we didn't hook that up to any event.

69
00:03:55,040 --> 00:03:59,030
So we actually have the right rotate there with the parentheses.

70
00:03:59,030 --> 00:04:00,500
Let's hit the play button.

71
00:04:00,510 --> 00:04:01,700
Let's see what we got.

72
00:04:04,440 --> 00:04:06,770
And there's our coin and it's moving.

73
00:04:06,780 --> 00:04:08,100
It's moving kind of slow.

74
00:04:08,130 --> 00:04:11,490
I want to speed it up a little bit so I turn this off.

75
00:04:13,480 --> 00:04:20,590
And I'm going to change this rotation to ten degree increments and then see how that works.

76
00:04:25,520 --> 00:04:27,570
Yeah, that's a little bit better.

77
00:04:27,590 --> 00:04:31,820
Now, if you make the wait longer, you're going to get, like, choppy movement.

78
00:04:31,820 --> 00:04:34,200
And I'll show you how to do twinning, too.

79
00:04:34,220 --> 00:04:35,390
That's like an animation.

80
00:04:35,390 --> 00:04:36,580
It's a smooth movement.

81
00:04:36,590 --> 00:04:39,080
We also have to smooth things down.

82
00:04:39,080 --> 00:04:40,460
We'll do both of those.

83
00:04:40,460 --> 00:04:43,130
But right now, this is going to be sufficient.

84
00:04:43,580 --> 00:04:44,900
So here's our loop.

85
00:04:44,900 --> 00:04:47,210
But we want to do special powers, too.

86
00:04:47,540 --> 00:04:48,650
I'm going to go to the coin.

87
00:04:48,650 --> 00:04:52,310
I'm going to add another script, hit that, plus add the script.

88
00:04:52,310 --> 00:04:55,790
And this one is going to be collect, right?

89
00:04:57,340 --> 00:04:58,720
The collect script.

90
00:04:58,750 --> 00:05:00,290
Let's go ahead and get a variable.

91
00:05:00,310 --> 00:05:01,460
Just like in our rotate.

92
00:05:01,480 --> 00:05:05,920
Local coin equals script dot parent.

93
00:05:06,190 --> 00:05:12,400
And then we'll make a function local function called on collect.

94
00:05:12,430 --> 00:05:15,760
The other part will be the part that collects the coin.

95
00:05:15,760 --> 00:05:16,780
That touches the coin.

96
00:05:16,780 --> 00:05:20,500
So this is essentially a touched event that we're capturing.

97
00:05:20,500 --> 00:05:23,350
So coin dot touched.

98
00:05:23,380 --> 00:05:30,700
Connect that to on collect get rid of the two parentheses here because when we're connecting an event

99
00:05:30,700 --> 00:05:33,100
to a function, we only need the function name.

100
00:05:33,640 --> 00:05:33,970
All right.

101
00:05:33,970 --> 00:05:35,980
So now other part could be anything, right?

102
00:05:35,980 --> 00:05:36,820
It could be a ball.

103
00:05:36,820 --> 00:05:38,680
It could be a tree.

104
00:05:39,160 --> 00:05:45,400
We need something associated with the humanoid because the humanoid changes the walk, speed and the

105
00:05:45,400 --> 00:05:47,410
jump power, just like the health.

106
00:05:47,410 --> 00:05:47,770
Right.

107
00:05:47,800 --> 00:05:49,390
Humanoids do a lot of stuff.

108
00:05:49,390 --> 00:05:53,020
So I'm going to call that Luke HUME or local HUME.

109
00:05:54,250 --> 00:05:56,380
Other part dot parent.

110
00:05:56,380 --> 00:05:57,960
So this is a hand or a foot.

111
00:05:57,970 --> 00:05:59,470
The parent is the character.

112
00:05:59,470 --> 00:06:08,020
We'll do a colon, find first child, double quote, humanoid, right?

113
00:06:08,020 --> 00:06:12,100
So if we find the humanoid, it's going to be right here in that variable.

114
00:06:12,100 --> 00:06:13,990
If we don't find it, it's going to be nil.

115
00:06:14,110 --> 00:06:15,120
So I'll say if.

116
00:06:15,130 --> 00:06:26,860
HUME Then HUME Dot, we're going to use something called jump power, but something new in Roblox we

117
00:06:26,860 --> 00:06:33,610
actually have to have this flag use jump power set to true, right?

118
00:06:33,610 --> 00:06:34,410
That's new.

119
00:06:34,420 --> 00:06:40,150
One of the reasons why I recreated this video, it used to not be there when used when use jump power

120
00:06:40,150 --> 00:06:41,170
is set to true.

121
00:06:41,170 --> 00:06:47,140
Now what we can do is say jump power equals and give it a value.

122
00:06:47,350 --> 00:06:52,060
If you want you can look at your humanoid, find that jump power, see what the normal one is.

123
00:06:52,090 --> 00:06:57,520
It's 50, so I'm going to make this 153 times the jump power.

124
00:06:58,000 --> 00:07:04,180
We also have walk speed in your humanoid and that normally is 16.

125
00:07:04,180 --> 00:07:10,930
I'm going to make this 50 so we can run real fast and then I'm going to get my coin and I'm going to

126
00:07:10,930 --> 00:07:11,980
destroy it.

127
00:07:13,710 --> 00:07:14,520
Cool.

128
00:07:15,090 --> 00:07:16,560
Let's see what happens.

129
00:07:17,220 --> 00:07:18,180
Hit the play.

130
00:07:22,010 --> 00:07:22,880
There's our coin.

131
00:07:22,880 --> 00:07:23,990
It's still spinning.

132
00:07:23,990 --> 00:07:25,190
We have two scripts on it.

133
00:07:25,200 --> 00:07:27,050
If we look in the workspace, open up the coin.

134
00:07:27,050 --> 00:07:29,750
There's two scripts where I go ahead and touch it.

135
00:07:30,170 --> 00:07:30,570
Boom!

136
00:07:30,650 --> 00:07:34,490
Oh, we run real fast, jump real high, and the coin is gone.

137
00:07:35,150 --> 00:07:36,890
All right, that's pretty cool.

138
00:07:36,890 --> 00:07:39,260
So I'm going to save this coin off.

139
00:07:40,620 --> 00:07:42,120
Go to my base plate.

140
00:07:42,880 --> 00:07:44,450
I'm going to make it a model first.

141
00:07:44,470 --> 00:07:45,880
I'm going to right click.

142
00:07:46,060 --> 00:07:47,920
I'm going to say group.

143
00:07:47,920 --> 00:07:48,310
Right.

144
00:07:48,310 --> 00:07:52,720
Even though the top level was only one was only one thing called a coin.

145
00:07:52,750 --> 00:07:56,170
I'm going to put it inside a model, which is like a fancy type of folder.

146
00:07:56,200 --> 00:07:58,210
I'm going to call that coin.

147
00:07:58,990 --> 00:07:59,250
All right.

148
00:07:59,260 --> 00:08:04,500
And you could just save this off as the part with stuff underneath, but people usually don't.

149
00:08:04,510 --> 00:08:06,230
So I right click on that.

150
00:08:06,250 --> 00:08:08,020
Here we go a little quick.

151
00:08:08,020 --> 00:08:11,620
Saved a Roblox coin.

152
00:08:11,740 --> 00:08:13,780
You can put a description.

153
00:08:13,810 --> 00:08:22,930
I'll say something like a coin with jump and run powers also rotates.

154
00:08:26,010 --> 00:08:28,770
You could distribute to marketplace so other people could get it.

155
00:08:28,890 --> 00:08:30,780
Or you could just hit submit.

156
00:08:31,470 --> 00:08:32,340
There we go.

157
00:08:32,700 --> 00:08:38,100
Now, when you go to your toolbox and you look under that, I saved another one off.

158
00:08:38,100 --> 00:08:39,660
I saved my shack off, too.

159
00:08:39,690 --> 00:08:42,460
We also need to save our health stuff.

160
00:08:42,480 --> 00:08:44,930
This is under your inventory.

161
00:08:44,940 --> 00:08:46,410
This is Marketplace.

162
00:08:47,380 --> 00:08:51,980
And this is inventory and now we can just drag the coin in the world if we need it.

163
00:08:52,000 --> 00:08:55,810
And it warns you that there are two scripts, but you wrote those scripts, so you're fine.

164
00:08:55,840 --> 00:08:57,040
There it is way out there.

165
00:08:57,580 --> 00:08:59,380
And you can move it around and do stuff with it.

166
00:09:00,130 --> 00:09:00,550
All right.

167
00:09:00,550 --> 00:09:02,500
So I will see you in the next video.

168
00:09:02,500 --> 00:09:08,110
We will do a while loop that's configurable and we'll have a break condition in it.